package com.jms;

import java.util.Date;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.json.JSONObject;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class Jms_producer {

	public static void main(String[] args) throws Exception {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		final JSONObject json = new JSONObject();
		json.put("timestamp", new Date());
		json.put("itemName", "鸡腿汉堡");
		json.put("unitPrice", "5");
		json.put("amount", "20");
		JmsTemplate template =(JmsTemplate)context.getBean("jmsTemplate");
		template.send(new MessageCreator(){

			public Message createMessage(Session sen) throws JMSException {
				TextMessage msg = sen.createTextMessage(json.toString());
				return msg;
			}
			
		});

	}
}
